<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>修改角色信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <script type="text/javascript" src="/js/cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="update">

        <div class="layui-input-inline">
            <input type="hidden" id="roleId" name="roleId" required=""
                   autocomplete="off" readonly class="layui-input">
        </div>


        <div class="layui-form-item">
            <label for="roleName" class="layui-form-label">
                角色名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="roleName" name="roleName" required=""
                       autocomplete="off" class="layui-input"lay-verify="required" >
            </div>
        </div>
        <div class="layui-form-item">
            <label for="roleKey" class="layui-form-label">
                权限字符
            </label>
            <div class="layui-input-inline">
                <input type="text" name="roleKey" id="roleKey"
                       autocomplete="off" class="layui-input"
                       lay-verify="required" />

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                角色状态
            </label>
            <div class="layui-input-inline" id="rStatus">
                <input type="radio" value="0" name="status" title="正常"/>
                <input type="radio" value="1" name="status" title="停用"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                备注
            </label>
            <div class="layui-input-inline">
                <input type="text" name="remark" id="remark" autocomplete="off" class="layui-input"/>
            </div>
        </div>

        <div class="layui-form-item" style="text-align: center">
            <button class="layui-btn" lay-filter="edit" lay-submit="">
                提交修改
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        var $ = layui.jquery;
        $(function ($) {
            var form = layui.form
                , layer = layui.layer;
            // 获取父窗口中存储的下拉框选中的值
            var select = parent.$("#rStatus").val();
            $("input:radio[value='" + select + "']").prop("checked", true);
            //渲染表单中的下拉框！！
            form.render('radio');
            //监听提交
            form.on('submit(edit)', function (data) {
                //发异步，把数据提交给后台
                //获取到表单数据
                //data.field为表单中的数据！
                $.ajax({
                    url: '/role/edit',
                    type: 'POST',
                    data: $('#update').serialize(),
                    success: function (res) {
                        if (res.status == 0) {
                            layer.closeAll('loading');
                            layer.load(2);
                            layer.alert("修改成功", {icon: 6}, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                                parent.location.reload();
                            });
                        } else {
                            layer.alert("修改失败", {icon: 5})
                        }
                    },
                })
                return false;

            });

        });

    });
</script>

</body>

</html>